Skip to content

Extend options stdlib #24849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open

Extend options stdlib #24849

wants to merge 1 commit into from

Conversation

Nycto
Copy link
Contributor

@Nycto Nycto commented Apr 5, 2025

This changes adds more procs to the options stdlib. These are convenience functions that make life easier when interacting with Options -- I've wound up adding them to just about every app I have written with Nim.

@Nycto Nycto force-pushed the options branch 2 times, most recently from eca83a3 to ee24d96 Compare April 7, 2025 15:10
@Nycto
Copy link
Contributor Author

Nycto commented May 3, 2025

The failure being reported in CI is:

 tests/stdlib/thttpclient_ssl.nim c

Failure: reExitcodesDiffer
Expected:
exitcode: 0

Gotten:
exitcode: 1

Output:

[Suite] SSL self signed certificate check
    [1746287859.487293] server: ready
    [1746287859.5890162] client: connect
    [1746287859.5897272] server: incoming connection
    [1746287859.5898144] server: accepting connection
C0F6BF7BB47F0000:error:0A000418:SSL routines:ssl3_read_bytes:tlsv1 alert unknown ca:../ssl/record/rec_layer_s3.c:1599:SSL alert number 48
    [1746287859.6046548] server: receiving a line
    [1746287859.705398] client: connect
    [1746287859.7056324] client: unexpected exception: Connection refused
  [FAILED] HttpClient default: no check
    [1746287859.811127] server: ready
    [1746287859.9555795] server: ready
    [1746287859.9844153] client: connect
    [1746287859.9847176] server: incoming connection
    [1746287859.9848032] server: accepting connection
    [1746287859.9955516] client: exception: error:0A000086:SSL routines::certificate verify failed
C0F63F7BB47F0000:error:0A000418:SSL routines:ssl3_read_bytes:tlsv1 alert unknown ca:../ssl/record/rec_layer_s3.c:1599:SSL alert number 48
    [1746287859.9997697] server: receiving a line
    [1746287859.9997885] server: received 0 bytes
    [1746287859.999796] closing
    [1746287859.99985] server: exited
    [1746287860.1011178] client: connect
    [1746287860.1013148] client: exception: Connection refused
    [1746287860.1013272] getContent should not have raised an exception
  [FAILED] HttpClient with CVerifyPeerUseEnvVars

I may be missing something, but that seems unrelated to the change in this PR

@Araq
Copy link
Member

Araq commented May 4, 2025

I may be missing something, but that seems unrelated to the change in this PR

Correct, don't worry.

@arnetheduck
Copy link
Contributor

for results, I've been planning to reuse tricks like https://github.com/nim-lang/Nim/blob/version-2-2/lib/pure/collections/sequtils.nim#L97 to avoid most of the extra copies that are unnecessary - this implementation is very heavy on copies in general, often in a way that is tricky for the compiler to get rid of.

a second trick to use is to verify that the code efficiently moves data around and/or uses cursors where applicable, ie in Option[string], withValue should not copy the string inside the some case when it already has a stack copy of the Option instance, or this implementation will defeat one of the main purposes of using it, namely to work with values without said overhead. Imagine using it with a 10mb string.

@arnetheduck
Copy link
Contributor

In particular, see https://github.com/arnetheduck/nim-results/blob/df8113dda4c2d74d460a8fa98252b0b771bf1f27/results.nim#L1430 for a much more efficient way to inject a variable into a template - there is also a variation on the same theme when genericsopensym is not enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants